//导入axios
//创建axios
import axios from "axios";
//1.配置基地址
const instance = axios.create({
  baseURL: "http://api.imooc.hybrid.lgdsunday.club/",
  //2.请求超时
  timeout: 5000,
});

//请求拦截器
instance.interceptors.request.use(
  (config) => {
    config.params = {
      token: "595fe950-7ebd-11ed-aa1f-dd279271aa3a",
    };
    // console.log(token);
    //必须返回config，这样的请求才能到达到服务器，否则请求失败
    return config;
  },
  (error) => {
    //对请求错误做些什么
    return Promise.reject(error);
  }
);
//响应拦截器
instance.interceptors.response.use(
  function (response) {
    // console.log(response);
    return response.data;
  },
  (err) => {
    return Promise.reject(err);
  }
);
//导入请求实例
export default instance;
